//
//  LrcParse.m
//  27-AVPlayer
//
//  Created by Snow on 16/8/20.
//  Copyright © 2016年 Snow. All rights reserved.
//

#import "LrcParse.h"

@implementation LrcParse
- (instancetype)init{
    self = [super init];
    if (self) {
        self.timeArray = [NSMutableArray array];
        self.wordArray = [NSMutableArray array];
    }
    return self;
}

-(void)parserLrc {
    
    NSString *path = [[NSBundle mainBundle] pathForResource:@"12月24日" ofType:@"lrc"];
    NSURL *url = [NSURL fileURLWithPath:path];
    //转换 C 字符串
    NSString *lrc = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil];
    
    if (![lrc isEqual:nil]) {
        NSArray *sepArray = [lrc componentsSeparatedByString:@"["];
        NSArray *lineArray = [[NSArray alloc] init];
        for (int i = 0; i < sepArray.count; i++) {
            if ([sepArray[i] length] > 0) {
                lineArray = [sepArray[i] componentsSeparatedByString:@"]"];
                if (![lineArray[0] isEqualToString:@"\n"]) {
                    [self.timeArray addObject:lineArray[0]];
                    [self.wordArray addObject:lineArray.count > 1 ? lineArray[1] : @""];
                }
            }
        }
    }
}
@end
